<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<script>
    function Stack(){
        this.data=[];
        this.top=0;
    }
    Stack.prototype={
        constructor:Stack,
        push: function (elm) {
            this.data[this.top++]=elm;
        },
        pop: function () {
            return this.data[--this.top];
        },
        peek: function () {
            return this.data[this.top-1];
        },
        size: function () {
            return this.top;
        },
        clear: function () {
            delete this.data;
            this.data=[];
            this.top=0;
        }
    }

    function mulBase(num,base){
        var s=new Stack(),converted='';
        do{
            s.push(num%base);
            num=Math.floor(num/base);
        }while(num>0);
        while(s.size()>0){
            converted+= s.pop();
        }
        return converted;
    }

    console.log(mulBase(32,2));
    console.log(mulBase(125,8));
    console.log(mulBase(12345,10));
</script>
</body>
</html>